Skip to content

Add Julia native loggamma functionality#128

Closed
TSGut wants to merge 13 commits intoJuliaMath:masterfrom
TSGut:master
Closed

Add Julia native loggamma functionality#128
TSGut wants to merge 13 commits intoJuliaMath:masterfrom
TSGut:master

Conversation

@TSGut
Copy link
Copy Markdown

@TSGut TSGut commented Apr 6, 2026

In light of discussions at https://discourse.julialang.org/t/ann-meijerg-jl-a-julia-package-for-calculating-meijer-g-functions/136577 and locally in this repo at #27, here is an adaptation of loggamma based on pre-existing as well as my recent work in SpecialFunctions.jl (JuliaMath/SpecialFunctions.jl#522).

loggamma for reals and bigfloat calls external libraries in SpecialFunctions.jl, so I adapted Julia native versions as part of this. The real bigfloat version just reroutes to the Complex BigFloat one for now but if we care that can be changed for some significant speedups in that route in the future.

I don't know where the best place is to discuss where this goes - the issue, Julia discourse, etc. Or maybe this can restart conversations about a renaming of this package to something more general and thus SEO friendly?

Very happy for feedback or comments.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.09%. Comparing base (4ff4d61) to head (c9bedc4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #128      +/-   ##
==========================================
+ Coverage   95.72%   96.09%   +0.36%     
==========================================
  Files          24       25       +1     
  Lines        2385     2585     +200     
==========================================
+ Hits         2283     2484     +201     
+ Misses        102      101       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TSGut
Copy link
Copy Markdown
Author

TSGut commented Apr 6, 2026

Alright, tests pass, coverage passes. The only thing failing is invalidations which as far as I can tell has nothing to do with my PR, it didn't add invalidations I think there is some version incompatibility in the action which causes an error?

@heltonmc What's the PR process for this package? I would be happy for a review or suggestions.

Also @juliohm and @oscardssmith since they were part of the chat on Julia Discourse.

Things I intend to leave for the future for now:

  1. Dedicated real BigFloat branch rather than using the slower Complex{BigFloat} logic.
  2. Export loggammas and gammas? Rebrand? Make Gamma.jl elsewhere? Not sure which if any of this is desirable.

@juliohm
Copy link
Copy Markdown

juliohm commented Apr 6, 2026

Thank you for leading this @TSGut ! @oscardssmith is more qualified to help with a review.

Hope this initiative will get the attention it deserves from package authors and maintainers in JuliaMath 🙏🏽

@TSGut
Copy link
Copy Markdown
Author

TSGut commented Apr 6, 2026

Benchmarking the implementations with the strategy suggested by the readme I get (compared to ArbNumerics.jl):

Function Type Metric Value
loggamma Float64 Mean relative error 2.602362769721367e-16
loggamma Float64 Max relative error 3.674838211509268e-14
loggamma ComplexF64 Mean relative error 1.3655212256834891e-16
loggamma ComplexF64 Max relative error 4.869646413689727e-16
logabsgamma Float64 Mean relative error 2.602362769721367e-16
logabsgamma Float64 Max relative error 3.674838211509268e-14

And execution time is roughly the same as using SpecialFunctions.jl:

Function Type Library Mean (ns) Median (ns) Std (ns) Speedup
loggamma Float64 Bessels 8.87 8.84 0.17 1.011×
loggamma Float64 SpecialFunctions 9.00 8.94 0.16 1.000×
loggamma ComplexF64 Bessels 28.79 28.78 0.14 1.010×
loggamma ComplexF64 SpecialFunctions 29.08 29.05 0.22 1.000×
logabsgamma Float64 Bessels 10.49 10.54 0.23 0.832×
logabsgamma Float64 SpecialFunctions 8.80 8.77 0.30 1.000×

@TSGut
Copy link
Copy Markdown
Author

TSGut commented Apr 7, 2026

@oscardssmith: I think this covers everything in your code review -- anything else left to do before this can be merged?

I leave it to you whether you choose to export these functions but the sooner this can be tagged the sooner I can get started on making the hypergeometric functions be Julia native. 😄 I have had a chat with the maintainer of HypergeometricFunctions.jl and he's happy for me to basically copy and adjust his code as functions within MeijerG.jl, so MeijerG.jl will just contain its own native hypergeometric function logic and probably also export a Julia native pFq, with its only dependency becoming Bessels.jl.

@oscardssmith
Copy link
Copy Markdown
Member

The code looks good to me, but I do think or should probably live in a new Gamma.jl. there are a ton more people that likely will want a good gamma function (e.g. Primes.jl) that probably don't want to pull in all the bessel functions as well.

@TSGut
Copy link
Copy Markdown
Author

TSGut commented Apr 7, 2026

I am happy to do that, can you make a Gamma.jl in JuliaMath (we should check that no such named package is currently registered)? While we're at it could I be added to JuliaMath - would make this easier going forward.

I'll move this code into a PR for the new Gamma.jl then.

Also, if this will create a new Julia native Special functions ecosystem then we probably want to have references pointing at the other relevant packages in that ecosystem from the readmes or docs.

@oscardssmith
Copy link
Copy Markdown
Member

https://github.com/JuliaMath/Gamma.jl. If you make the PR, I'll work on getting this to be an actual Julia repo.

@TSGut
Copy link
Copy Markdown
Author

TSGut commented Apr 7, 2026

Great, I will close this PR since we are moving development there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants